/*
 * Copyright © 2016-2019 WAWSCM Inc. All rights reserved.
 */
package com.wawscm.service.impl;

import com.wawscm.BaseSpringTestCase;
import com.wawscm.mapper.UserInfoMapper;
import com.wawscm.model.UserInfo;
import com.wawscm.service.UserService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;

/**
 * Test for {@link UserServiceImpl}
 *
 * @author Wang Chengwei
 * @since 1.0.0
 */
@Transactional
@Rollback
public class UserServiceImplTestWithoutDbData extends BaseSpringTestCase {

    @Autowired
    private UserService userService;

    @Autowired
    private UserInfoMapper userInfoMapper;

    private static final String USER_ID = "48454645645648786KLDJKGLD000";

    @Before
    public void setUp() {
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(USER_ID);
        userInfo.setPhoneNumber("11100000000");
        userInfo.setAccountMergeState((byte) 0);
        userInfo.setPoints(1000);
        this.userInfoMapper.insert(userInfo);
    }

    @Test
    public void addPoint() {
        userService.addPoint(USER_ID, 100);
        UserInfo userInfo = this.userInfoMapper.selectByPrimaryKey(USER_ID);
        assertThat(userInfo).hasFieldOrPropertyWithValue("points", 1100);
    }

}